/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.ruby_string.delayed;

import moved.org.objectweb.asm.MethodVisitor;
import picounit.util.Equal;
import picounit.verify.constraint.EqualUtil;

public class Annotation extends AbstractMethodInstruction implements Equal<Annotation> {
	private final String name;
	private final boolean visible;
	private final DelayedAnnotationMutator delayedAnnotationMutator;

	public Annotation(String name, boolean visible,
		DelayedAnnotationMutator delayedAnnotationMutator) {

		this.name = name;
		this.visible = visible;
		this.delayedAnnotationMutator = delayedAnnotationMutator;
	}
	
	public boolean matches(String name, boolean visible) {
		return this.name.equals(name) &&
			this.visible == visible;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// Equal methods
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	public boolean equalTo(Annotation other) {
		return other.matches(name, visible);
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// MethodInstruction Methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	public void accept(MethodVisitor methodVisitor) {
		delayedAnnotationMutator.accept(methodVisitor.visitAnnotation(name, visible));
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// Object Methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	@Override
	public boolean equals(Object object) {
		return EqualUtil.isEqual(this, object);
	}
	
	@Override
	public int hashCode() {
		return getClass().hashCode();
	}
	
	@Override
	public String toString() {
		return "VisibleAnnotation: " + name + ", " + visible;
	}
}
